package com.paolocorno.datatable;

import java.util.Comparator;

/**
 *
 * @author Paolo Corno
 */
public class DataTableRecordComparator implements Comparator<AbstractDataTableRecord> {

    String name = "";
    int index = 0;

    /**
     *
     * @param index
     */
    public DataTableRecordComparator(int index) {
        this.index = index;
        this.name = "";
    }

    /**
     *
     * @param name
     */
    public DataTableRecordComparator(String name) {
        this.index = -1;
        this.name = name;
    }

    @Override
    public int compare(AbstractDataTableRecord o1, AbstractDataTableRecord o2) {
        if (name.isEmpty()) {
            return o1.compareTo(o2, index);
        } else {
            return o1.compareTo(o2, name);
        }
    }
}
